import { defineEventHandler, getQuery } from 'h3';

// 模拟资源详情数据
const mockResourceDetails = {
  '1': {
    id: '1',
    name: '酒店管理系统',
    type: 'service',
    category: 'hotel',
    version: '1.0.0',
    status: 'active',
    description:
      '完整的酒店管理解决方案，包含预订、入住、退房、财务管理等核心功能',
    tags: ['酒店', '管理', 'PMS', '预订'],
    attributes: {
      capacity: '1000间房',
      features: ['预订', '入住', '退房', '财务', '报表', '会员管理'],
      integration: ['微信', '支付宝', '携程', '美团', '飞猪'],
      technology: ['Vue3', 'Node.js', 'MySQL', 'Redis'],
      deployment: ['Docker', 'Kubernetes'],
    },
    capabilities: [
      {
        id: 'booking',
        name: '预订管理',
        type: 'workflow',
        description: '支持在线预订、修改、取消',
        version: '1.0.0',
        config: {
          maxAdvanceDays: 365,
          allowModification: true,
          allowCancellation: true,
        },
        enabled: true,
      },
      {
        id: 'room-management',
        name: '房态管理',
        type: 'service',
        description: '实时房态监控和管理',
        version: '1.0.0',
        config: {
          realTimeSync: true,
          autoUpdate: true,
        },
        enabled: true,
      },
      {
        id: 'finance',
        name: '财务管理',
        type: 'service',
        description: '收入统计、成本分析、财务报表',
        version: '1.0.0',
        config: {
          multiCurrency: true,
          taxCalculation: true,
        },
        enabled: true,
      },
    ],
    constraints: {
      maxRooms: 1000,
      maxUsers: 50,
      regions: ['CN'],
      compliance: ['数据安全', '隐私保护'],
      performance: {
        responseTime: '<2s',
        uptime: '99.9%',
        concurrentUsers: 100,
      },
    },
    pricing: {
      customerPricing: {
        currency: 'CNY',
        basePrice: 999,
        unit: 'month',
        features: ['基础功能', '技术支持', '培训'],
        tiers: [
          {
            name: '基础版',
            price: 599,
            features: ['基础功能'],
          },
          {
            name: '标准版',
            price: 999,
            features: ['基础功能', '技术支持'],
          },
          {
            name: '高级版',
            price: 1999,
            features: ['完整功能', '技术支持', '培训', '定制开发'],
          },
        ],
      },
      platformPricing: {
        currency: 'CNY',
        cost: 299,
        margin: 700,
        revenueShare: 0.3,
        commission: 0.1,
      },
    },
    lifecycle: {
      status: 'active',
      createdAt: '2024-01-01T00:00:00Z',
      updatedAt: '2024-01-15T10:30:00Z',
      publishedAt: '2024-01-10T09:00:00Z',
      version: '1.0.0',
      changelog: [
        {
          version: '1.0.0',
          date: '2024-01-10',
          changes: ['初始版本发布', '基础功能实现'],
        },
      ],
    },
    metadata: {
      author: 'HotelTech',
      license: 'commercial',
      documentation: 'https://docs.hoteltech.com',
      support: 'support@hoteltech.com',
      website: 'https://hoteltech.com',
      repository: 'https://github.com/hoteltech/pms',
      dependencies: ['Node.js 16+', 'MySQL 8.0+', 'Redis 6.0+'],
      requirements: ['4GB RAM', '50GB Storage', 'Linux/Windows'],
    },
    usage: {
      totalInstalls: 150,
      activeInstalls: 120,
      totalRevenue: 150000,
      averageRating: 4.5,
      reviews: 45,
    },
    dependencies: [
      {
        id: 'payment-gateway',
        name: '支付网关',
        version: '1.0.0',
        required: true,
      },
      {
        id: 'notification-service',
        name: '通知服务',
        version: '1.0.0',
        required: false,
      },
    ],
  },
  '2': {
    id: '2',
    name: '宠物店管理系统',
    type: 'service',
    category: 'pet',
    version: '0.9.0',
    status: 'draft',
    description: '宠物店业务管理平台，支持宠物档案、服务预约、商品管理等功能',
    tags: ['宠物', '零售', '管理', '预约'],
    attributes: {
      capacity: '500宠物',
      features: ['宠物档案', '服务预约', '商品管理', '会员管理'],
      integration: ['微信', '支付宝', '美团'],
      technology: ['Vue3', 'Node.js', 'MongoDB'],
    },
    capabilities: [
      {
        id: 'pet-profile',
        name: '宠物档案管理',
        type: 'service',
        description: '宠物信息记录和管理',
        version: '0.9.0',
        config: {
          photoUpload: true,
          medicalHistory: true,
        },
        enabled: true,
      },
      {
        id: 'appointment',
        name: '服务预约',
        type: 'workflow',
        description: '美容、医疗等服务预约',
        version: '0.9.0',
        config: {
          maxAdvanceDays: 30,
          reminderNotification: true,
        },
        enabled: true,
      },
    ],
    constraints: {
      maxPets: 500,
      maxUsers: 20,
      regions: ['CN'],
      compliance: ['动物保护法'],
    },
    pricing: {
      customerPricing: {
        currency: 'CNY',
        basePrice: 599,
        unit: 'month',
        features: ['基础功能'],
      },
      platformPricing: {
        currency: 'CNY',
        cost: 199,
        margin: 400,
        revenueShare: 0.25,
      },
    },
    lifecycle: {
      status: 'draft',
      createdAt: '2024-01-12T14:30:00Z',
      updatedAt: '2024-01-15T16:20:00Z',
      publishedAt: null,
      version: '0.9.0',
    },
    metadata: {
      author: 'PetTech',
      license: 'commercial',
      documentation: 'https://docs.pettech.com',
      support: 'support@pettech.com',
    },
    usage: {
      totalInstalls: 0,
      activeInstalls: 0,
      totalRevenue: 0,
      averageRating: 0,
      reviews: 0,
    },
  },
};

export default defineEventHandler(async (event) => {
  const query = getQuery(event);
  const { id } = query;

  if (!id) {
    return {
      success: false,
      message: '资源ID不能为空',
    };
  }

  const resourceDetail = mockResourceDetails[id as string];

  if (!resourceDetail) {
    return {
      success: false,
      message: '资源不存在',
    };
  }

  return {
    success: true,
    data: resourceDetail,
    message: '查询成功',
  };
});
